package com.freight.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.order.dto.CommonLineDto;
import com.freight.order.service.CompanyCommonLineService;
import com.freight.order.vo.CommonLineListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@Api(description = "货主端 --- 常用路线")
@RequestMapping("/freight/companyOrderCommonLine")
@Transactional
public class CompanyCommonLineController {

    @Autowired
    private CompanyCommonLineService appcCommonLineService;


    @RequestMapping(value = "/addCommonLine", method = RequestMethod.POST)
    @ApiOperation(value = "添加、修改常用路线")
    public Result<String> addCommonLine(CommonLineDto commonLineDto) {
        appcCommonLineService.addCommonLine(commonLineDto);
        return ResultUtil.data("操作成功");
    }

    @RequestMapping(value = "/deleteCommonLine", method = RequestMethod.POST)
    @ApiOperation(value = "删除常用路线")
    public Result<String> deleteCommonLine(Long id) {
        appcCommonLineService.deleteCommonLine(id);
        return ResultUtil.data("操作成功");
    }

    @RequestMapping(value = "/getCommonLine", method = RequestMethod.POST)
    @ApiOperation(value = "获取常用路线列表")
    public Result<Page<CommonLineListVo>> getCommonLine(PageVo page, String beginAreaCode, String endAreaCode) {
        Page<CommonLineListVo> list = appcCommonLineService.getCommonLinePage(PageUtil.initMpPage(page), beginAreaCode, endAreaCode);
        return new ResultUtil<Page<CommonLineListVo>>().setData(list);
    }



}
